package com.gzs.learn.payment.algorithm;

import com.gzs.learn.inf.split.SplitIdUtil;

/**
 * 分表算法
 * 
 * @author guanzhisong
 * @date 2021-08-17
 */
public class TableShardingAlgorithm extends BaseShardingAlgorithm {
    private static final int PAYMENT_TABLE_COUNT = SplitIdUtil.PAYMENT_TABLE_SPLIT;
    private static final int PAYMENT_TABLE_SHIFT = PAYMENT_TABLE_COUNT - 1;
    private static final int TABLE_SHIFT = 0b00000111;

    @Override
    long getActualTarget(long shardingTarget) {
        long tableKey = shardingTarget & TABLE_SHIFT;
        return tableKey & PAYMENT_TABLE_SHIFT;
    }
}
